﻿using System;
using System.Globalization;
using System.Web.Mvc;
using Isaac.Joy.Cms.Module;
using UIShell.OSGi;

namespace Isaac.Joy.Cms.Controllers
{
    public class ProductController : Controller
    {
        private readonly IRepository _repository;
        public ProductController()
        {
            _repository = BundleRuntime.Instance.GetFirstOrDefaultService<IRepository>();
        }

        public ActionResult Index()
        {
            var list = _repository.QueryAll();
            return View(list);
        }

        public ActionResult Add()
        {
            var product = new Product
            {
                Name = new Random().Next(100).ToString(CultureInfo.InvariantCulture),
                Price = new Random().Next(10)
            };

            _repository.AddProduct(product);

            return Content("OK");
        }
    }
}
